package Dao;

import DataClass.CurrentStudent;
import Util.JBDCUtil;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CurrentStudentDao {

    private static PreparedStatement preparedStatement = null;
    public static List<CurrentStudent> getCurrentStudent() throws SQLException {
        List<CurrentStudent> list = new ArrayList<>();

        ResultSet data = CurrentStudentDao.getDataCurrentStudent();

        while (data.next()) {
            String SNo = data.getString("SNo");
            String SCName = data.getString("SCName");
            String SSex = data.getString("SSex");
            String SType = data.getString("SType");
            String SNation = data.getString("SNation");
            String STNo = data.getString("STNo");
            String SATNo = data.getString("SATNo");
            int SEnter = data.getInt("SEnter");
            String photoPath = "studentPhoto.jpg";
            list.add(new CurrentStudent(SNo, SCName, SSex, SType, SNation, STNo, SATNo, SEnter, photoPath));
        }
        return list;
    }

    public static ResultSet getDataCurrentStudent() throws SQLException {
        if(preparedStatement == null)
        {
            String sql = "select * from Student where SOut is NULL";
            preparedStatement = JBDCUtil.getPreparedStatement(sql);
        }

        ResultSet data = preparedStatement.executeQuery();
        JBDCUtil.commit();
        return data;
    }
}
